﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace VERKProjectHopur16.Models
{
    public class ContentViewModel
    {
        #region Repository instance
        DataRepository m_rep = new DataRepository();
        #endregion

        #region Constructor
        public ContentViewModel()
        {
            Categories = new List<SelectListItem>();
            foreach (var categ in m_rep.GetAllCateg())
            {
                Categories.Add(new SelectListItem { Text = categ.Name, Value = categ.CategoryID.ToString() });
            }
            Categories.Add(new SelectListItem { Text = "-Select-", Value = "", Selected = true });

            Departments = new List<SelectListItem>();
            foreach (var dept in m_rep.GetAllDept())
            {
                Departments.Add(new SelectListItem { Text = dept.Name, Value = dept.DepartmentID.ToString() });
            }
            Departments.Add(new SelectListItem { Text = "-Select-", Value = "", Selected = true });

            Authors = new List<SelectListItem>();
            foreach (var author in m_rep.GetAllAuthors())
            {
                Authors.Add(new SelectListItem { Text = author.Name, Value = author.AuthorID.ToString() });
            }
            Authors.Add(new SelectListItem { Text = "-Select-", Value = "", Selected = true });

            Languages = new List<SelectListItem>();
            foreach (var language in m_rep.GetAllLang())
            {
                Languages.Add(new SelectListItem { Text = language.Name, Value = language.LanguageID.ToString() });
            }
            Languages.Add(new SelectListItem { Text = "-Select-", Value = "", Selected = true });
        }
        #endregion

        #region Properties
        public int ContentID { get; set; }

        [Required(ErrorMessage = "Field required")]
        public String Title { get; set; }

        [Required(ErrorMessage = "Field required")]
        public String Text { get; set; }

        [Required(ErrorMessage = "Field required")]
        public String AuthorID { get; set; }

        [Required(ErrorMessage = "Field required")]
        public String DepartmentID { get; set; }

        [Required(ErrorMessage = "Field required")]
        public String CategoryID { get; set; }

        [Required(ErrorMessage = "Field required")]
        public String LanguageID { get; set; }

        public List<SelectListItem> Categories { get; set; }

        public List<SelectListItem> Departments { get; set; }

        public List<SelectListItem> Authors { get; set; }

        public List<SelectListItem> Languages { get; set; }
        #endregion
    }
}